import { awaitWrap } from '@/libs/tools'
import ajax from '@/libs/ajax'
import { fromFetch } from '@/libs/utils'

const config = {
  baseURL: '/iap',
}

const http = ajax(config, { request: false })

const API_BASE = ''
const _basePath = (url) => {
  return `${API_BASE}${url}`
}

const api = {
  sendSms: _basePath('/iap/captcha/sendSms'),
  generateCaptcha: _basePath('/generateCaptcha'),
  deployInfo: _basePath('/tenant/basicInfo'),
  doLogin: _basePath('/iap/doLogin'),
  doLoginMobile: _basePath('/iap/doLoginMobile'),
  security: _basePath('/iap/security/lt'),
  doForce: _basePath('/iap/doForce'),
  checkPassRule: _basePath('/iap/checkPassRule'),
}

export const sendSms = async (params) => {
  return awaitWrap(fromFetch(api.sendSms, params))
}
export const generateCaptcha = async (params) => {
  return http.get(api.generateCaptcha, { params })
}
export const deployInfo = async (params) => {
  return awaitWrap(http.post(api.deployInfo, params))
}
export const doLogin = async (params) => {
  return fromFetch(api.doLogin, params)
}
export const doLoginMobile = async (params) => {
  return fromFetch(api.doLoginMobile, params)
}
export const doForce = async (params) => {
  return fromFetch(api.doForce, params)
}
export const checkPassRule = async (params) => {
  return fromFetch(api.checkPassRule, params)
}
export const security = async (params) => {
  return awaitWrap(fromFetch(api.security, params))
}

export const LogoInfo = async (params) => {
  return http.post('/tenant/info', params)
}
